//
//  ZJRequestManager.m
//  ZhongWangYuanApp
//
//  Created by ZJ on 2018/6/3.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "ZJRequestManager.h"

@implementation ZJRequestManager


+ (void)request_getCoursewareInfoWithID:(NSString *)ID successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    [paramer setValue:ID forKey:@"id"];
    [paramer setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    [YBAFNetWorkingTool postWithUrlString:@"selectFrontCoursewareById" Parameter:paramer Success:successBlock Fail:failBlock];
}

+ (void)request_getCoursewareTeacherInfoWithID:(NSString *)ID successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    [paramer setValue:ID forKey:@"id"];
    [paramer setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    [YBAFNetWorkingTool postWithUrlString:@"selectTeachersByCoursewareId" Parameter:paramer Success:successBlock Fail:failBlock];
}

+ (void)request_getCoursewareIsCommentWithID:(NSString *)ID successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    [paramer setValue:ID forKey:@"id"];
    [YBAFNetWorkingTool postWithUrlString:@"geAppraisetFlag" Parameter:paramer Success:successBlock Fail:failBlock];
}

+ (void)request_getCoursewareCollectWithCoursewareIdArray:(NSArray *)coursewareIdArray successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    
    NSString * scoreListString = @"[]";
    
    if (coursewareIdArray.count > 0) {
        NSMutableArray * fullArray = [NSMutableArray array];
        [coursewareIdArray enumerateObjectsUsingBlock:^(NSString *  _Nonnull coursewareid, NSUInteger idx, BOOL * _Nonnull stop) {
            NSString *string = [NSString stringWithFormat:@"{\"coursewareid\":\"%@\",\"studentid\":\"%@\"}",coursewareid,YBUSERINFOMODEL.studentId];
            [fullArray addObject:string];
        }];
        scoreListString =[NSString stringWithFormat:@"[%@]" , [fullArray componentsJoinedByString:@","]];
    }
    
    [paramer setValue:scoreListString forKey:@"courseCollection"];
    
    [YBAFNetWorkingTool postWithUrlString:@"insertCourseWareCollectionForApp" Parameter:paramer Success:successBlock Fail:failBlock];
}



+ (void)request_getCoursewareCancelCollectWithCoursewareIdArray:(NSArray *)coursewareIdArray successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    
    NSString * scoreListString = @"[]";
    
    if (coursewareIdArray.count > 0) {
        NSMutableArray * fullArray = [NSMutableArray array];
        [coursewareIdArray enumerateObjectsUsingBlock:^(NSString *  _Nonnull coursewareid, NSUInteger idx, BOOL * _Nonnull stop) {
            NSString *string = [NSString stringWithFormat:@"{\"coursewareid\":\"%@\",\"studentid\":\"%@\"}",coursewareid,YBUSERINFOMODEL.studentId];
            [fullArray addObject:string];
        }];
        scoreListString =[NSString stringWithFormat:@"[%@]" , [fullArray componentsJoinedByString:@","]];
    }
    
    [paramer setValue:scoreListString forKey:@"courseCollection"];
    
    [YBAFNetWorkingTool postWithUrlString:@"deleteCourseWareCollectionForApp" Parameter:paramer Success:successBlock Fail:failBlock];
}


+ (void)request_getCoursePlayerBeginWithCoursewareid:(NSString *)coursewareid courwarestudytime:(NSString *)courwarestudytime successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    [paramer setValue:coursewareid forKey:@"coursewareid"];
    [paramer setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    [paramer setValue:courwarestudytime forKey:@"courwarestudytime"];
    
    [YBAFNetWorkingTool postWithUrlString:@"getVideoLogPKey" Parameter:paramer Success:successBlock Fail:failBlock];
}

+ (void)request_getCoursePlayerSaveScheduleWithCoursewareid:(NSString *)coursewareid
                                                       time:(NSString *)time
                                                       pkey:(NSString *)pkey
                                              videoDuration:(NSString *)videoDuration
                                          courwarestudytime:(NSString *)courwarestudytime
                                                 playerTime:(NSString *)playerTime
                                             coursewarename:(NSString *)coursewarename
                                                  currentID:(NSString *)currentID
                                             studetailcount:(NSString *)studetailcount
                                                    classId:(NSString *)classId
                                               successBlock:(NetBlock)successBlock
                                                  failBlock:(NetBlock)failBlock{
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    NSArray *array = [NSString getArrayFromString:time byString:@"."];
    time = array.firstObject;
//    pkey 视频播放记录主键
//    studentid 登录的用户ID
//    coursewareid 课程ID
//    currentID 每次退出该课程进入播放页面，新生成一个guid.
//    time 视频当前播放位置的时间线（秒）
//    timestamp用户实际视频观看的时间，除去拖拽的进度，调用视频接口 j2s_realPlayVideoTime 获取的
//    studytime 与time 的一样。
//    videoDuration 视频时间时长
//    accountid  帐号ID
//    studetailcount 随currentID变化，当currentID发生变化的第一次提交数据时为0，数据成功后变成1，后面一直是1，直到该门课程播放完成或者发生切课。
//    courwarestudytime 课程学时
//    coursewarename 课程名称
    [paramer setValue:pkey forKey:@"pkey"];
    [paramer setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    [paramer setValue:time forKey:@"time"];
    [paramer setValue:currentID forKey:@"currentID"];
    [paramer setValue:playerTime forKey:@"timestamp"];
    [paramer setValue:videoDuration forKey:@"videoDuration"];
    [paramer setValue:coursewareid forKey:@"coursewareid"];
    [paramer setValue:YBUSERINFOMODEL.accountId forKey:@"accountid"];
    [paramer setValue:studetailcount forKey:@"studetailcount"];
    [paramer setValue:courwarestudytime forKey:@"courwarestudytime"];
    [paramer setValue:coursewarename forKey:@"coursewarename"];
    [paramer setValue:time forKey:@"studytime"];
    [paramer setValue:@"iphone" forKey:@"clienttype"];
    [paramer setValue:@"" forKey:@"xtcoursewareid"];
    [paramer setValue:classId forKey:@"classid"];
    [YBAFNetWorkingTool postWithUrlString:@"videoplayforapp" Parameter:paramer Success:successBlock Fail:failBlock];
}

+ (void)request_getCourseAddAwaitStudyWithCoursewareid:(NSString *)coursewareid successBlock:(NetBlock)successBlock failBlock:(NetBlock)failBlock{
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    [paramer setValue:coursewareid forKey:@"coursewareid"];
    [paramer setValue:YBUSERINFOMODEL.studentId forKey:@"studentid"];
    
    [YBAFNetWorkingTool postWithUrlString:@"inertToBeStudiedUseWeicatApp" Parameter:paramer Success:successBlock Fail:failBlock];
}


@end
